Skip to content

Stream active notification content attributes in recorder-safe buckets#6801

Draft
Komzpa wants to merge 3 commits into
home-assistant:mainfrom
Komzpa:codex/active-notification-attrs-default-off
Draft

Stream active notification content attributes in recorder-safe buckets#6801
Komzpa wants to merge 3 commits into
home-assistant:mainfrom
Komzpa:codex/active-notification-attrs-default-off

Conversation

@Komzpa

@Komzpa Komzpa commented May 3, 2026

Copy link
Copy Markdown

Summary

  • Keep Active notification count content attributes enabled by default.
  • Split active notification contents into recorder-safe buckets when the payload would be too large for Home Assistant recorder.
  • Preserve existing installs by removing the migration that disabled the content-attributes setting.

Why

When one device has many active notifications, sending every notification as attributes on a single state update can exceed Home Assistant recorder's state-attribute size limit. In that case recorder warns and does not store the oversized attributes.

This keeps the numeric notification count stable while sending the content attributes as multiple forced updates. Each update has the same total count and a small part marker, so recorder can store the full snapshot across history rows. Buckets are sent oldest first; the last/current bucket contains the newest notifications.

Bucket metadata uses short keys:

  • total: total active notifications
  • part: current bucket number, starting at 1
  • parts: total bucket count
  • last: whether this is the final bucket
  • snapshot: shared id for all buckets from one update
  • cut / cut_count: present only if oversized content had to be trimmed

Testing

  • git diff --check
  • ./gradlew :app:ktlintCheck :common:ktlintCheck
  • ./gradlew :common:compileDebugAndroidTestKotlin
  • ./gradlew :app:testFullDebugUnitTest --tests 'io.homeassistant.companion.android.sensors.NotificationSensorManagerTest'

@Komzpa
Komzpa force-pushed the codex/active-notification-attrs-default-off branch from e12a782 to d6f6e19 Compare May 14, 2026 03:55
@Komzpa
Komzpa marked this pull request as ready for review May 24, 2026 21:41
Copilot AI review requested due to automatic review settings May 24, 2026 21:41

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Note

Copilot was unable to run its full agentic suite in this review.

Updates the active notification count sensor to default to not collecting notification content attributes, and migrates existing installs to disable the setting and clear any cached notification content.

Changes:

  • Change the active notification content-attributes setting default from true to false.
  • Add a Room database migration (51 → 52) that disables the setting, deletes cached attributes, and forces a resend.
  • Add an Android migration test and bump Room schema/version to 52.

Reviewed changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
common/src/main/res/values/strings.xml Updates the sensor description text to remove the “enabled by default” claim.
common/src/main/kotlin/io/homeassistant/companion/android/database/migration/DatabaseMigration.kt Adds migration 51→52 to disable the setting, clear stored attributes, and reset last-sent state/icon.
common/src/main/kotlin/io/homeassistant/companion/android/database/AppDatabase.kt Bumps Room DB version to 52.
common/src/androidTest/kotlin/io/homeassistant/companion/android/database/migration/AppDatabaseMigrationTest.kt Adds an instrumentation test validating the 51→52 migration behavior.
common/schemas/io.homeassistant.companion.android.database.AppDatabase/52.json Adds the Room schema snapshot for version 52.
app/src/main/kotlin/io/homeassistant/companion/android/sensors/NotificationSensorManager.kt Changes the runtime default for including notification contents as attributes to false.

applicationContext,
activeNotificationCount,
SETTING_INCLUDE_CONTENTS_AS_ATTRS,
default = true,

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's a breaking change, @jpelgrom how do you handle such thing in the past? Users relying on this at the moment will have to go in the settings and enable it back. It might break some automations.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Adjusted this so it no longer disables the setting for existing users or changes the default to off.

The current version keeps active_notification_count_content_attrs enabled by default and removes the 51 → 52 migration entirely. Instead, when the notification content payload is too large for recorder, the app sends the same count across multiple forced bucket updates with short part / parts / snapshot metadata. That keeps existing automations from losing the content attributes while keeping each recorded state payload below the recorder size limit.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's a breaking change, @jpelgrom how do you handle such thing in the past? Users relying on this at the moment will have to go in the settings and enable it back. It might break some automations.

Generally we don't touch settings for sensors once created. When changing it in code it won't change it in the database by default, unless you add a migration as was done here before the entire overhaul.

@TimoPtr
TimoPtr marked this pull request as draft May 26, 2026 07:26
@Komzpa Komzpa changed the title Default active notification content attributes to off Stream active notification content attributes in recorder-safe buckets May 26, 2026
@jpelgrom

Copy link
Copy Markdown
Member

Personally speaking, this bucket behavior is very convoluted and once again highlights how this shouldn't be accommodated in a sensor. It also duplicates sending logic in the actual sensor which is unwanted.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants